package com.tiancheng.trade.settlement.task;

import com.tiancheng.trade.commom.core.utils.DateTimeUtil;
import com.tiancheng.trade.settlement.service.settlement.IPaymentBankDataCmbService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

/**
 * 定时任务，处理支付对账数据
 */
@Component
@Slf4j
public class PaymentBankDataTask {
    static final String PAYMENT_BANK_DATA = "定时处理支付对账数据";

    @Autowired
    IPaymentBankDataCmbService paymentBankDataCmbService;

    /**
     * 处理支付流水对账数据,招商银行
     */
    @XxlJob("handlePaymentBankDataCmb")
    public ReturnT<String> handlePaymentBankDataCmb(String param) {
        log.info(PAYMENT_BANK_DATA + " 开启");
        try {
            LocalDate localDate = LocalDate.now().plusDays(-1);
            if (StringUtils.isNotEmpty(param)) {
                localDate = DateTimeUtil.formatDate(param, "yyyyMMdd");
            }
            paymentBankDataCmbService.getAndSavePayCsv(localDate);
        } catch (Exception e) {
            log.error(PAYMENT_BANK_DATA + "，出现异常", e, e);
        }
        log.info(PAYMENT_BANK_DATA + " 结束");
        return ReturnT.SUCCESS;
    }

}
